home *** CD-ROM | disk | FTP | other *** search
/ Champak 74 / Volume 74 My Disc - Damaged.iso / Games / shape_escape.swf / scripts / mochi / MochiScores.as next >
Text File  |  2008-08-07  |  7KB  |  228 lines

  1. package mochi
  2. {
  3.    import flash.display.MovieClip;
  4.    import flash.display.Sprite;
  5.    import flash.text.TextField;
  6.    
  7.    public class MochiScores
  8.    {
  9.       
  10.       private static var boardID:String;
  11.       
  12.       public static var onErrorHandler:Object;
  13.       
  14.       public static var onCloseHandler:Object;
  15.        
  16.       
  17.       public function MochiScores()
  18.       {
  19.          super();
  20.       }
  21.       
  22.       public static function showLeaderboard(param1:Object = null) : void
  23.       {
  24.          var options:Object = param1;
  25.          if(options != null)
  26.          {
  27.             if(options.clip != null)
  28.             {
  29.                if(options.clip is Sprite)
  30.                {
  31.                   MochiServices.setContainer(options.clip);
  32.                }
  33.                delete options.clip;
  34.             }
  35.             else
  36.             {
  37.                MochiServices.setContainer();
  38.             }
  39.             MochiServices.stayOnTop();
  40.             if(options.name != null)
  41.             {
  42.                if(options.name is TextField)
  43.                {
  44.                   if(options.name.text.length > 0)
  45.                   {
  46.                      options.name = options.name.text;
  47.                   }
  48.                }
  49.             }
  50.             if(options.score != null)
  51.             {
  52.                if(options.score is TextField)
  53.                {
  54.                   if(options.score.text.length > 0)
  55.                   {
  56.                      options.score = options.score.text;
  57.                   }
  58.                }
  59.             }
  60.             if(options.onDisplay != null)
  61.             {
  62.                options.onDisplay();
  63.             }
  64.             else if(MochiServices.clip != null)
  65.             {
  66.                if(MochiServices.clip is MovieClip)
  67.                {
  68.                   MochiServices.clip.stop();
  69.                }
  70.                else
  71.                {
  72.                   trace("Warning: Container is not a MovieClip, cannot call default onDisplay.");
  73.                }
  74.             }
  75.          }
  76.          else
  77.          {
  78.             options = {};
  79.             if(MochiServices.clip is MovieClip)
  80.             {
  81.                MochiServices.clip.stop();
  82.             }
  83.             else
  84.             {
  85.                trace("Warning: Container is not a MovieClip, cannot call default onDisplay.");
  86.             }
  87.          }
  88.          if(options.onClose != null)
  89.          {
  90.             onCloseHandler = options.onClose;
  91.          }
  92.          else
  93.          {
  94.             onCloseHandler = function():void
  95.             {
  96.                if(MochiServices.clip is MovieClip)
  97.                {
  98.                   MochiServices.clip.play();
  99.                }
  100.                else
  101.                {
  102.                   trace("Warning: Container is not a MovieClip, cannot call default onClose.");
  103.                }
  104.             };
  105.          }
  106.          if(options.onError != null)
  107.          {
  108.             onErrorHandler = options.onError;
  109.          }
  110.          else
  111.          {
  112.             onErrorHandler = null;
  113.          }
  114.          if(options.boardID == null)
  115.          {
  116.             if(MochiScores.boardID != null)
  117.             {
  118.                options.boardID = MochiScores.boardID;
  119.             }
  120.          }
  121.          MochiServices.send("scores_showLeaderboard",{"options":options},null,onClose);
  122.       }
  123.       
  124.       public static function closeLeaderboard() : void
  125.       {
  126.          MochiServices.send("scores_closeLeaderboard");
  127.       }
  128.       
  129.       public static function getPlayerInfo(param1:Object, param2:Object = null) : void
  130.       {
  131.          MochiServices.send("scores_getPlayerInfo",null,param1,param2);
  132.       }
  133.       
  134.       public static function requestList(param1:Object, param2:Object = null) : void
  135.       {
  136.          MochiServices.send("scores_requestList",null,param1,param2);
  137.       }
  138.       
  139.       public static function scoresArrayToObjects(param1:Object) : Object
  140.       {
  141.          var _loc2_:Object = null;
  142.          var _loc3_:Number = NaN;
  143.          var _loc4_:Number = NaN;
  144.          var _loc5_:Object = null;
  145.          var _loc6_:Object = null;
  146.          var _loc7_:* = null;
  147.          var _loc8_:* = null;
  148.          _loc2_ = {};
  149.          for(_loc7_ in param1)
  150.          {
  151.             if(typeof param1[_loc7_] == "object")
  152.             {
  153.                if(param1[_loc7_].cols != null && param1[_loc7_].rows != null)
  154.                {
  155.                   _loc2_[_loc7_] = [];
  156.                   _loc5_ = param1[_loc7_];
  157.                   _loc4_ = 0;
  158.                   while(_loc4_ < _loc5_.rows.length)
  159.                   {
  160.                      _loc6_ = {};
  161.                      _loc3_ = 0;
  162.                      while(_loc3_ < _loc5_.cols.length)
  163.                      {
  164.                         _loc6_[_loc5_.cols[_loc3_]] = _loc5_.rows[_loc4_][_loc3_];
  165.                         _loc3_++;
  166.                      }
  167.                      _loc2_[_loc7_].push(_loc6_);
  168.                      _loc4_++;
  169.                   }
  170.                }
  171.                else
  172.                {
  173.                   _loc2_[_loc7_] = {};
  174.                   for(_loc8_ in param1[_loc7_])
  175.                   {
  176.                      _loc2_[_loc7_][_loc8_] = param1[_loc7_][_loc8_];
  177.                   }
  178.                }
  179.             }
  180.             else
  181.             {
  182.                _loc2_[_loc7_] = param1[_loc7_];
  183.             }
  184.          }
  185.          return _loc2_;
  186.       }
  187.       
  188.       public static function submit(param1:Number, param2:String, param3:Object = null, param4:Object = null) : void
  189.       {
  190.          MochiServices.send("scores_submit",{
  191.             "score":param1,
  192.             "name":param2
  193.          },param3,param4);
  194.       }
  195.       
  196.       public static function onClose(param1:Object = null) : void
  197.       {
  198.          if(param1 != null)
  199.          {
  200.             if(param1.error != null)
  201.             {
  202.                if(param1.error == true)
  203.                {
  204.                   if(onErrorHandler != null)
  205.                   {
  206.                      if(param1.errorCode == null)
  207.                      {
  208.                         param1.errorCode = "IOError";
  209.                      }
  210.                      onErrorHandler(param1.errorCode);
  211.                      MochiServices.doClose();
  212.                      return;
  213.                   }
  214.                }
  215.             }
  216.          }
  217.          onCloseHandler();
  218.          MochiServices.doClose();
  219.       }
  220.       
  221.       public static function setBoardID(param1:String) : void
  222.       {
  223.          MochiScores.boardID = param1;
  224.          MochiServices.send("scores_setBoardID",{"boardID":param1});
  225.       }
  226.    }
  227. }
  228.